<body>
<div id=banner style="clear:both;width:100%;display:block;">
	<div style="width:80%;">
	<h4>
	Rayson is a Java common communication module for cloud computing.
	With Rayson, we can call the remote service just using a java proxy interface, without care about any underling socket communication things.
	</h4>
	</div>
	<div style="float:right;width:20%;text-align:right">
		<img src="doc-files/rayson.png" />
	</div>
</div>
<div style="text-align:left;">
<ul>
	<li type=1>
	First, we define a RPC protocol interface.
	<div class=code>
		<pre>		
		public interface DemoProtocol extends RpcProtocol
		{
			public String echo(String message) throws NullPointerException, RpcException;
		}		
		</pre>
	</div>
	</li>
	<li type=1>
	Second, we define a RPC service interface that extends the above protocol interface.
	<div class=code>
		<pre>
		public interface DemoService extends RpcService, DemoProtocol
		{
		}
		</pre>
	</div>
	</li>
		<li type=1>
	we define class that implements the above service interface.
	<div class=code>
		<pre>
		public class DemoServiceImpl implements DemoService
		{
			\@Override
			public String echo(String message) throws NullPointerException
			{
				return message;
			}
			\@Override
			public boolean isSupportedVersion(Session session)
			{
				return true;
			}
		}
		</pre>
	</div>
	</li>
	<li type=1>
	we construct a instance of above class, and register it to a RPC server.
	<div class=code>
		<pre>
			int portNumber = 5500;
			RpcServer rpcServer = new RpcServer(portNumber);
			rpcServer.start();
			rpcServer.registerService("demo", "Demo service",
					new DemoServiceImpl());
		</pre>
	</div>
	</li>
	<li type=1>
	Finally , we call the remote service using the above protocol interface in the client side.
	<div class=code>
		<pre>
		InetSocketAddress serverAddress = new InetSocketAddress(InetAddress.getLocalHost(), 5500);
		DemoProtocol testRpcProxy = Rayson.createProxy("demo", DemoProtocol, serverAddress);
		System.out.println(testRpcProxy.echo("hello world"));
		</pre>
	</div>
	</li>	
</ul>
</div>
<div>
<h4>High performance</h4>
Rayson use only one listener thread to handle the underling socket channel asynchronous read and write events in both server and client side, so it has a great performance in communication in both client side and server side.
<h4>Asynchronous support</h4>
Rayson support for invoking RPC all asynchronously. For example:
<div class=code>
		<pre>	
		AsyncRpcProtocol asyncProxy = Rayson.createAsyncProxy("demo",AsyncRpcProtocol.class, serverAddress);
		CallFuture<String> echoFuture = asyncProxy.echo("Async call echo message");
		System.out.println("Async call echo:" + echoFuture.get());
		//DemoAsyncProxy definition
		public interface DemoAsyncProxy extends AsyncRpcProtocol {
		
		        public CallFuture<String> echo(String message) throws NetWorkException;
		}
</pre>
	</div>
<h4>Stream based communication support</h4>
Rayson also support stream based communication mode.
Register stream based service (transfer service) to server.
<div class=code>
		<pre>	
	   transportServer.registerService(new DemoTransferService());
	   //DemoTransferService definition
	   public class DemoTransferService implements
	                TransferService<DemoTransferArgument> {
	
	        \@Override
	        public void process(DemoTransferArgument argument, TransferSocket socket)
	                        throws IOException {
	                System.out.println("TransferSocket read int: "
	                                + socket.getDataInput().readInt());
	        }
	
	        \@Override
	        public boolean isSupportedVersion(short clientVersion) {
	                return false;
	        }
	}
</pre>
	</div>
<h4>Call demo transfer service on client side.</h4>
<div class=code>
		<pre>	
		TransferSocket transferSocket = Rayson.openTransferSocket(
		                                serverAddress, new DemoTransferArgument("testPath"));
		transferSocket.getDataOutput().writeInt(1456);
		transferSocket.close();
		</pre>
</div>
</div>
</body>